﻿function initGrid(grid)
{
   for(i in grid.rows)
   {
        if(grid.rows[i].tagName != null)
        {
            if(grid.rows[i].tagName.toLowerCase() == "tr")
            {
                grid.rows[i].onmouseover = highlightRow;
                grid.rows[i].onmouseout = unhighlightRow;
                grid.rows[i].onclick = selectRow;
            }
        }
    }
}

function selectRow(row)
{
    row = getElementForEvent(row);
    row.style.backgroundColor="red";
}

function highlightRow(row)
{
    row = getElementForEvent(row);
    row.style.backgroundColor="yellow";
}

function unhighlightRow(row)
{
    row = getElementForEvent(row);
    row.style.backgroundColor="";
}

function getElementForEvent(e)
{
    var targ;
    if (!e)
    {
      var e=window.event;
    }
    if (e.target)
    {
      targ=e.target;
    }
    else if (e.srcElement)
    {
      targ=e.srcElement;
    }
    if (targ.nodeType==3) // defeat Safari bug
    {
      targ = targ.parentNode;
    }

    return targ;
}